<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>天城用工</title>
    <link rel="stylesheet" type="text/css" href="../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/font/iconfont.css" />
    <style type="text/css">
        html,
        body {
            background: #fff;
        }

        .iconfont {
            font-size: 1rem !important;
        }

        .aui-bar-tab-item img {
            display: inline-block;
            width: 1.2rem;
            margin: 0.1rem 0 0.2rem 0;
        }
    </style>
</head>

<body>

    <!-- <header class="aui-bar aui-bar-nav" id="header">
        <div class="aui-pull-left aui-btn">
        </div>
        <div class="aui-title">首页</div>
    </header> -->
</body>
<script src="../script/api.js"></script>
<script src='../script/common/jquery-3.3.1.min.js'></script>
<script src='../script/common/common.js'></script>
<script src='../script/common/config.js'></script>
<script type="text/javascript">
    apiready = function() {
        api.parseTapmode();
        var header = $api.byId('header');
        // 设置沉浸式和透明背景
        set_BarStyle("light", "rgba(0,0,0,0)");
        //监听手机返回退出app
        exit_app();
        // //获取用户位置
        // getUserLocation();
        //打开页面组
        NVTabBar_open();
    }

    // 自定义底部导航
    function NVTabBar_open() {
        var NVTabBar = api.require('NVTabBar');
        // alert(NVTabBar)
        NVTabBar.open({
            styles: {
                bg: 'rgba(255,255,255,1)',
                h: 54,
                dividingLine: {
                    width: 1,
                    color: '#f0f0f0'
                },
                badge: {
                    bgColor: '#2cd7de',
                    numColor: '#000',
                    size: 6.0,
                    centerY: 2
                }
            },
            items: [{
                w: api.winWidth * 0.19,
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/icon/menu01.png',
                    highlight: 'widget://image/icon/menu01.png',
                    selected: 'widget://image/icon/menu01-1.png'
                },
                title: {
                    text: '首页',
                    size: 12.0,
                    normal: '#BFBFBF',
                    selected: '#0689FB',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth * 0.19,
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/icon/menu02.png',
                    highlight: 'widget://image/icon/menu02.png',
                    selected: 'widget://image/icon/menu02-1.png'
                },
                title: {
                    text: '找工人',
                    size: 12.0,
                    normal: '#BFBFBF',
                    selected: '#0689FB',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth * 0.24,
                bg: {
                    marginB: 10,
                    image: 'rgba(200,200,200,0)'
                },
                iconRect: {
                    w: 55,
                    h: 55,
                },
                icon: {
                    normal: 'widget://image/icon/menu03.png',
                    highlight: 'widget://image/icon/menu03.png',
                    selected: 'widget://image/icon/menu03.png'
                },
                title: {
                    text: '发布',
                    size: 12.0,
                    normal: '#BFBFBF',
                    selected: '#0689FB',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth * 0.19,
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/icon/zhaoyewu.png',
                    highlight: 'widget://image/icon/zhaoyewu.png',
                    selected: 'widget://image/icon/zhaoyewuactive.png'
                },
                title: {
                    text: '找业务',
                    size: 12.0,
                    normal: '#BFBFBF',
                    selected: '#0689FB',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth * 0.19,
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/icon/menu05.png',
                    highlight: 'widget://image/icon/menu05.png',
                    selected: 'widget://image/icon/menu05-1.png'
                },
                title: {
                    text: '我的',
                    size: 12.0,
                    normal: '#BFBFBF',
                    selected: '#0689FB',
                    marginB: 6.0
                }
            }],
            selectedIndex: 0
        }, function(ret, err) {
            if (ret) {
                // 随时获取用户信息，即使更新缓存
                api.execScript({
                    frameName: 'my',
                    script: 'vm.gerUserInfo()'
                });
                if (ret.eventType == "click") {
                    // $('.aui-title').html(winInfo[ret.index].title);
                    var winInfo = setNavRouter(ret.index);
                    statusBar(winInfo.name, winInfo.url);
                } else {
                    var winInfo = setNavRouter(0);
                    statusBar(winInfo.name, winInfo.url);
                }
                // 模块置顶
                var NVTabBar = api.require('NVTabBar');
                NVTabBar.bringToFront();
            }
        });
    }

    function setSelectOption(index) {
        var NVTabBar = api.require('NVTabBar');
        NVTabBar.setSelect({
            index: index,
            selected: true,
        });
        var winInfo = setNavRouter(index);
        statusBar(winInfo.name, winInfo.url);
        // 模块置顶
        NVTabBar.bringToFront();
    }

    function setNavRouter(index) {
        var winInfo = {
            0: {
                name: 'home',
                url: './home/index.html',
                title: '首页'
            },
            1: {
                name: 'look_for_workers',
                url: './look_for_workers/index.html',
                title: '找工人'
            },
            2: {
                name: 'issued',
                url: './issued/index.html',
                title: '发布'
            },
            3: {
                name: 'bus_res',
                url: './home/bus_res/index.html',
                title: '找业务'
            },
            4: {
                name: 'my',
                url: './my/index.html',
                title: '我的'
            }
        };
        if (index === 2 || index === 3 || index === 4) {
            var islogin = isLogin();
            if (!islogin) {
                return false;
            }
        }
        return winInfo[index];
    }

    function statusBar(name, url) {
        // var frameheight = api.winHeight - 54 - $api.byId('header').offsetHeight;
        api.openFrame({
            name: name,
            url: url,
            rect: {
                x: 0,
                y: 0,
                h: api.winHeight - 54
            },
            // reload:true
        });
    }

    //获取用户位置
    function getUserLocation() {
        //获取用户坐标,api自带的是谷歌的,使用国货快！！！
        if (api.systemType == 'ios') {
            //不兼容ios 随便给个经纬度用
            var lon = 39.9144123454;
            var lat = 116.4044314011;
            getRegion(lon, lat);
        } else {
            //获取用户实际坐标信息
            var aMap = api.require('aMap');
            aMap.getLocation(function(ret, err) {
                if (ret.status) {
                    getRegion(ret.lon, ret.lat)
                }
            });
        }
    }

    //获取城市区域
    function getRegion(lon, lat) {
        _ajax(Config.api.HomeGetRegion, {
            longitude: lon,
            latitude: lat
        }, function(res) {
            if (res.code === 200) {
                res.data.lon = lon;
                res.data.lat = lat;
                set_local('user_region', res.data);
            }
        })
    }
</script>

</html>
